easy-rpc Syntax
easy-rpc uses a custom declaration language to specify the endpoints. In this section this language will be explained.
If you are looking for available configuration options to configure the
.json
files, see the configuration options..
Endpoints
Endpoints allways consist of at least a role and a name. This is the absolute minumum for a valid endpoint:
erpcBackend ping()
Endpoints can have parameters and return types. These can be any valid easy-rpc type.
erpc// Endpoint with a parameterBackend logToServerConsole(message string)// Endpoint with a return typeBackend getCurrentTime() int32// Endpoint with a signle parameter and return typeBackend echo(echoMessage string) string// Endpoint with multiple parameters and a return typeBackend sendMessageTo(message string, userId int) string
Types
There are three kinds of types in easy-rpc.
Primitive types
As in many other languages, easy-rpc knows a fixed set of primitive types.
Identifier | Description |
---|---|
boolean | A value which can be true or false |
int | A whole number (16bit) |
int8 | A whole number (8bit) |
int16 | A whole number (16bit) |
int32 | A whole number (32bit) |
int64 | A whole number (64bit) |
float | A floating point number (32bit) |
float32 | A floating point number (32bit) |
float64 | A floating point number (64bit) |
string | A string of characters |
Enum types
An enum value is a value which is one of a fixed set. Values are separated by a |
. Any valid easy-rpc type can be used.
erpcBackend example(enumParameter "example" | 420 | true | string | MyCustomType) "success" | "error"
Custom types
Custom types are user defined types consisting of other user defined types or primitive types.
erpctype ExampleType { field1 string field2 "ex" | "ample"}type AnotherType { field1 ExampleType}
Arrays
Primitive or user defined types can be arrays. Arrays are marked via a []
behind the type. Arrays can have a fixed size.
erpctype Player { name string achievements string[] levelsCompleted boolean[99]}
Optionals
Fields and parameters can be optional. This indicates, that the field or parameter might not be set. To mark a field or parameter as optional, suffix it with a questionmark
erpctype Player { name string secondName? string} Backend exampleEndpoint(requiredParameter string, optionalParameter? string)
Comments
easy-rpc allows for two kinds of comments: Disposeable and documentational. Disposeable comments are ignored while transpiling. Documentational comments are transferred into the generated types and methods.
erpc/** This represents a player of the game*/type Player { /** This comment will be documentational */ name string /* This one will be ignored */ achievements string[] // I'm going to be ignored levelsCompleted boolean[99] # Me too}/** This returns the player by their name*/Backend getPlayer(name string) Player